/**设置按钮 */
export const setButton = (json, tableData, configPageParams) => {
  const rowBtn = json.rowButtonList || [];
  const headBtn = json.headButtonList || [];
  setBtn(rowBtn, configPageParams);
  setBtn(headBtn, configPageParams);
  tableData.rowButtonList = rowBtn;
  tableData.headButtonList = headBtn;
};

const setBtn = (rowBtn, configPageParams) => {
  for (let item of rowBtn) {
    if (item?.hide) {
      // 如果是字符串那么装换为方法
      if (typeof item.hide === 'string') {
        const method = new Function('row', item.hide);
        item.hide = row => method(row);
      }
    }

    if (item?.display) {
      // 如果是字符串那么装换为方法
      if (typeof item.display === 'string') {
        const method = new Function('row', item.display);
        item.display = row => method(row);
      }
    }

    if (item?.methods) {
      if (typeof item.methods === 'string') {
        const method = new Function('row', 'index', 'configPageParams', item.methods);
        item.methods = (row, index) => method(row, index, configPageParams);
      }
    }
  }
};
